<!DOCTYPE HTML>
<html  xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" href="/lib/layui/css/layui.css"  media="all">
    <script type="text/javascript" src="/lib/layui/layui.js"></script>
    <script src="/js/area.js"></script>
    <title>编辑管理员 - 管理员管理 - H-ui.admin v3.1</title>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>管理信息</legend>
</fieldset>
<form class="layui-form" action="" data-validator-option="{theme:'simple_right'}">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <input type="text" id="aid" th:value="${session.employ.id}" hidden="hidden">
        <div class="layui-input-block" style="width: 250px;height: 30px">
            <input type="text" id="empname" readonly="true" th:value="${session.employ.emUsername}" name="title" lay-verify="username" autocomplete="off" placeholder="用户名" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">员工姓名</label>
        <div class="layui-input-block" style="width: 250px;height: 30px">
            <input type="text"id="emprelname" th:value="${session.employ.emRealname}" name="title" lay-verify="realname" autocomplete="off" placeholder="员工姓名" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block" id="sex" >
            <input type="text" id="sex1" th:value="${session.employ.emSex}" hidden="hidden">
            <input type="radio" name="sex" value="男" title="男">
            <input type="radio" name="sex" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登陆密码</label>
        <div class="layui-input-inline" style="width: 250px;height: 30px">
            <input type="password"id="pwd" readonly="true" style="background-color:#dddddd " th:value="${session.employ.emPassword}" name="title" lay-verify="realname" autocomplete="off" placeholder="员工姓名" class="layui-input">
        </div>
        <a class="layui-btn layui-btn-normal" href="javascript:;" id="update">修改密码</a>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-inline">
                <input type="tel" name="phone" id="phone" th:value="${session.employ.emPhone}" lay-verify="required|phone" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" name="email" id="email" th:value="${session.employ.emEmail}" lay-verify="email" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地址</label>

        <div class="layui-input-inline">
            <input type="text" name="address" id="address" th:value="${session.employ.emAddress}" class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="checkbox" id="sysData" th:value="${session.employ.emStatus}" name="sysData" lay-skin="switch" lay-filter="switchTest" lay-text="正常|禁用" checked="">
        </div>
    </div>
    <div class="layui-form-item" pane="">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-block">
            <input type="text" id="check" th:value="${session.employ.emRole}" hidden="hidden">
            <input type="radio" name="like1" lay-skin="primary"  value="管理员" title="管理员">
            <input type="radio" name="like1" lay-skin="primary"   value="财务员" title="财务员">
            <input type="radio" name="like1" lay-skin="primary"   value="仓管员" title="仓管员" >
            <input type="radio" name="like1" lay-skin="primary"   value="销售员"title="销售员" >
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn"  lay-submit="" lay-filter="update">修改</button>
        </div>
    </div>
</form>
<script>
    function getSelectValue() {   //获取省市县/区在area.js配置的地区编码
        var province = document.getElementById("province").value;
        var city = document.getElementById("city").value;
        var area = document.getElementById("area").value;


        alert(province.split('_', 1));
        alert(city.split('_', 1));
        alert(area);
    }
</script>
<script>
    var areaData = Area;
    var $form;
    var form ;
    var $
    layui.use(['form','jquery','laydate'],function (data) {
        $ = layui.jquery;
        form = layui.form;
        $form =$('form');
        loadProvince();
        var selectsex  = function () {
            var sex =$("#sex1").val();
            alert(sex);
            $("input[name=sex][value='男']").attr("checked", sex == '男' ? true: false)
            $("input[name=sex][value='女']").attr("checked", sex == '女' ? true: false)
        }
        selectsex();

        var selectrole =function(){
            var str =$("#check").val();
            $("input[name=like1][value='管理员']").attr("checked", str == '管理员' ? true: false)
            $("input[name=like1][value='财务员']").attr("checked", str == '财务员' ? true: false)
            $("input[name=like1][value='仓管员']").attr("checked", str == '仓管员' ? true: false)
            $("input[name=like1][value='销售员']").attr("checked", str == '销售员' ? true: false)


        }
        selectrole();
        var flag =$("#sysData").val();
        var selectflag = function(){
            alert("dsaas"+flag=='禁用')
            if (flag=='禁用'){
                $("input[name='sysData']").attr("checked",false);
            }if (flag=='正常'){
                $("input[name='sysData']").attr("checked",true);
            }

        }
        selectflag();
        form.render();
        var sid =$("#aid").val()
        $("#update").click(function () {

            layer.open({
                type:2,
                title:'修改密码',
                fix:false,
                maxmin:true,
                shadeClose:true,
                area:['600px','400px'],
                content:'/systemsetup/employ/updatepwd?id='+sid,
                end:function() {

                }
            });
        });
        form.on('switch(switchTest)',function () {
            if (this.checked?'true':'false'=='true'){
                layer.confirm('你确定要启用吗？',{
                    btn:['是','否']
                },function (index) {
                    var sel =document.getElementById("sysData");
                    sel.setAttribute("value","正常");
                    layer.close(index);
                })
            }else{
                layer.confirm('你确定要停用吗？',{
                    btn:['是','否']
                },function (index) {
                    var sel =document.getElementById("sysData");
                    sel.setAttribute("value","禁止");
                    layer.close(index);
                })
            }
        })

        form.on('submit(update)',function (data) {
                       console.log(data.elem)
            console.log(data.form)
            console.log(data.field)


            $.ajax({
                type:'get',
                url:'/systemsetup/employ/submitupdate',
                data:{
                    id:sid,
                    emUsername: $("#empname").val(),
                    emRealname:$("#emprelname").val(),
                    emRole:$("input[name='like1']:checked").val(),
                    emSex:$("input[name='sex']:checked").val(),
                    emPhone:$("#phone").val(),
                    emEmail:$("#email").val(),
                    emAddress:$("#address").val(),
                    emStatus:$("input:checkbox[name='sysData']:checked").val()=='正常' ? '正常':'禁用',


                },
                success:function (rest) {
                    if (rest==1){
                        parent.layer.msg('修改成功',{time:2000,icon:1});
                    }else {
                        parent.layer.msg("服务器繁忙请稍后再试",{time:2000,icon:2});
                    }
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.getUserPageList();
                    parent.layer.close(index);
                }

            })
            return false;
        })

    })
    //加载省数据   '_' + areaData[i].mallCityList.length + '_' + i +
    function loadProvince() {
        var proHtml = '';
        for (var i = 0; i < areaData.length; i++) {
            proHtml += '<option value="' + areaData[i].provinceCode + '_' + areaData[i].mallCityList.length + '_' + i +'">' + areaData[i].provinceName + '</option>';
        }
        //初始化省数据
        $form.find('select[name=province]').append(proHtml);
        form.render();
        form.on('select(province)', function(data) {
            $form.find('select[name=area]').html('<option value="">请选择县/区</option>').parent().hide();
            var value = data.value;
            var d = value.split('_');
            var code = d[0];
            var count = d[1];
            var index = d[2];
            if (count > 0) {
                loadCity(areaData[index].mallCityList);
            } else {
                $form.find('select[name=city]').parent().hide();
            }
        });
    }
    //加载市数据   '_' + citys[i].mallAreaList.length + '_' + i +
    function loadCity(citys) {
        var cityHtml = '';
        for (var i = 0; i < citys.length; i++) {
            cityHtml += '<option value="' + citys[i].cityCode + '_' + citys[i].mallAreaList.length + '_' + i +'">' + citys[i].cityName + '</option>';
        }
        $form.find('select[name=city]').html(cityHtml).parent().show();
        form.render();
        form.on('select(city)', function(data) {
            var value = data.value;
            var d = value.split('_');
            var code = d[0];
            var count = d[1];
            var index = d[2];
            if (count > 0) {
                loadArea(citys[index].mallAreaList);
            } else {
                $form.find('select[name=area]').parent().hide();

            }
        });
    }
    //加载县/区数据
    function loadArea(areas) {
        var areaHtml = '';
        for (var i = 0; i < areas.length; i++) {
            areaHtml += '<option value="' + areas[i].areaCode + '">' + areas[i].areaName + '</option>';
        }
        $form.find('select[name=area]').html(areaHtml).parent().show();
        form.render();
        form.on('select(area)', function(data) {
        });
    }




</script>
</body>
</html>